﻿
namespace NetROS.Tiers.Windows.Forms
{
	/// <summary>
	/// abstract ObracunVirman typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class ObracunVirmanDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<ObracunVirmanDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.ObracunVirman _currentObracunVirman = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxObracunVirmanDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxObracunVirmanErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxObracunVirmanBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the ID property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIDDataGridViewColumn;
		/// <summary> 
		/// the DGV column associated with the IDObracun property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxIDObracunDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the IDVirman property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIDVirmanDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
				
		private Entities.TList<Entities.Obracun> _IDObracunList;
		
		/// <summary> 
		/// The list of selectable Obracun
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.Obracun> IDObracunList
		{
			get {return this._IDObracunList;}
			set 
			{
				this._IDObracunList = value;
				this.uxIDObracunDataGridViewColumn.DataSource = null;
				this.uxIDObracunDataGridViewColumn.DataSource = this._IDObracunList;
			}
		}
		
		private bool _allowNewItemInIDObracunList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of Obracun
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInIDObracunList
		{
			get { return _allowNewItemInIDObracunList;}
			set
			{
				this._allowNewItemInIDObracunList = value;
				this.uxIDObracunDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.ObracunVirman> _ObracunVirmanList;
				
		/// <summary> 
		/// The list of ObracunVirman to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.ObracunVirman> ObracunVirmanList
		{
			get {return this._ObracunVirmanList;}
			set
			{
				this._ObracunVirmanList = value;
				this.uxObracunVirmanBindingSource.DataSource = null;
				this.uxObracunVirmanBindingSource.DataSource = value;
				this.uxObracunVirmanDataGridView.DataSource = null;
				this.uxObracunVirmanDataGridView.DataSource = this.uxObracunVirmanBindingSource;				
				//this.uxObracunVirmanBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxObracunVirmanBindingSource_ListChanged);
				this.uxObracunVirmanBindingSource.CurrentItemChanged += new System.EventHandler(OnObracunVirmanBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnObracunVirmanBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentObracunVirman = uxObracunVirmanBindingSource.Current as Entities.ObracunVirman;
			
			if (_currentObracunVirman != null)
			{
				_currentObracunVirman.Validate();
			}
			//_ObracunVirman.Validate();
			OnCurrentEntityChanged();
		}

		//void uxObracunVirmanBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.ObracunVirman"/> instance.
		/// </summary>
		public Entities.ObracunVirman SelectedObracunVirman
		{
			get {return this._currentObracunVirman;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxObracunVirmanDataGridView.VirtualMode;}
			set
			{
				this.uxObracunVirmanDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxObracunVirmanDataGridView.AllowUserToAddRows;}
			set {this.uxObracunVirmanDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxObracunVirmanDataGridView.AllowUserToDeleteRows;}
			set {this.uxObracunVirmanDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxObracunVirmanDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxObracunVirmanDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="ObracunVirmanDataGridViewBase"/> class.
		/// </summary>
		public ObracunVirmanDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxObracunVirmanDataGridView = new System.Windows.Forms.DataGridView();
			this.uxObracunVirmanBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxObracunVirmanErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIDDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxIDObracunDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			this.uxIDVirmanDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			//this.uxIDObracunBindingSource = new ObracunBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDObracunBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxObracunVirmanDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxObracunVirmanBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxObracunVirmanErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxObracunVirmanErrorProvider
			// 
			this.uxObracunVirmanErrorProvider.ContainerControl = this;
			this.uxObracunVirmanErrorProvider.DataSource = this.uxObracunVirmanBindingSource;						
			// 
			// uxObracunVirmanDataGridView
			// 
			this.uxObracunVirmanDataGridView.AutoGenerateColumns = false;
			this.uxObracunVirmanDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxObracunVirmanDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIDDataGridViewColumn,
		this.uxIDObracunDataGridViewColumn,
		this.uxIDVirmanDataGridViewColumn			});
			this.uxObracunVirmanDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxObracunVirmanDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxObracunVirmanDataGridView.Name = "uxObracunVirmanDataGridView";
			this.uxObracunVirmanDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxObracunVirmanDataGridView.TabIndex = 0;	
			this.uxObracunVirmanDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxObracunVirmanDataGridView.EnableHeadersVisualStyles = false;
			this.uxObracunVirmanDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnObracunVirmanDataGridViewDataError);
			this.uxObracunVirmanDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnObracunVirmanDataGridViewCellValueNeeded);
			this.uxObracunVirmanDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnObracunVirmanDataGridViewCellValuePushed);
			
			//
			// uxIDDataGridViewColumn
			//
			this.uxIDDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDDataGridViewColumn.DataPropertyName = "ID";
			this.uxIDDataGridViewColumn.HeaderText = "ID";
			this.uxIDDataGridViewColumn.Name = "uxIDDataGridViewColumn";
			this.uxIDDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDDataGridViewColumn.ReadOnly = true;		
			//
			// uxIDObracunDataGridViewColumn
			//
			this.uxIDObracunDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDObracunDataGridViewColumn.DataPropertyName = "IDObracun";
			this.uxIDObracunDataGridViewColumn.HeaderText = "IDObracun";
			this.uxIDObracunDataGridViewColumn.Name = "uxIDObracunDataGridViewColumn";
			this.uxIDObracunDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDObracunDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDObracunDataGridViewColumn.ReadOnly = false;		
			//
			// uxIDVirmanDataGridViewColumn
			//
			this.uxIDVirmanDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDVirmanDataGridViewColumn.DataPropertyName = "IDVirman";
			this.uxIDVirmanDataGridViewColumn.HeaderText = "IDVirman";
			this.uxIDVirmanDataGridViewColumn.Name = "uxIDVirmanDataGridViewColumn";
			this.uxIDVirmanDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDVirmanDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDVirmanDataGridViewColumn.ReadOnly = false;		
			//
			// uxIDObracunDataGridViewColumn
			//				
			this.uxIDObracunDataGridViewColumn.DisplayMember = "DatumOd";	
			this.uxIDObracunDataGridViewColumn.ValueMember = "ID";	
			this.uxIDObracunDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxIDObracunDataGridViewColumn.DataSource = uxIDObracunBindingSource;				
				
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxObracunVirmanDataGridView);
			this.Name = "ObracunVirmanDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDObracunBindingSource)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxObracunVirmanErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxObracunVirmanDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxObracunVirmanBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				ObracunVirmanDataGridViewEventArgs args = new ObracunVirmanDataGridViewEventArgs();
				args.ObracunVirman = _currentObracunVirman;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class ObracunVirmanDataGridViewEventArgs : System.EventArgs
		{
			private Entities.ObracunVirman	_ObracunVirman;
	
			/// <summary>
			/// the  Entities.ObracunVirman instance.
			/// </summary>
			public Entities.ObracunVirman ObracunVirman
			{
				get { return _ObracunVirman; }
				set { _ObracunVirman = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxObracunVirmanDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnObracunVirmanDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxObracunVirmanDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnObracunVirmanDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxObracunVirmanDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDDataGridViewColumn":
						e.Value = ObracunVirmanList[e.RowIndex].ID;
						break;
					case "uxIDObracunDataGridViewColumn":
						e.Value = ObracunVirmanList[e.RowIndex].IDObracun;
						break;
					case "uxIDVirmanDataGridViewColumn":
						e.Value = ObracunVirmanList[e.RowIndex].IDVirman;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxObracunVirmanDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnObracunVirmanDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxObracunVirmanDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDDataGridViewColumn":
						ObracunVirmanList[e.RowIndex].ID = (System.Int32)e.Value;
						break;
					case "uxIDObracunDataGridViewColumn":
						ObracunVirmanList[e.RowIndex].IDObracun = (System.Int32)e.Value;
						break;
					case "uxIDVirmanDataGridViewColumn":
						ObracunVirmanList[e.RowIndex].IDVirman = (System.Int32)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
